package com.guchenbo.example.image;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;

import java.io.*;

/**
 * @Author gucb
 * @Date 2017/5/15.
 */
public class ImageUtils {

    public static String encode(byte[] bytes) {
        return Base64.encodeBase64String(bytes);
    }

    public static void decode(String string, String filePath) {
        byte[] bytes = Base64.decodeBase64(string);
        try {
            OutputStream outputStream = new FileOutputStream(filePath);
            IOUtils.write(bytes, outputStream);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
